<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	

	<script>
       function accAdd(num1,num2){ // 两个浮点数求和保留n小树
	       var r1,r2,m;
	       try{
	           r1 = num1.toString().split('.')[1].length;
	       }catch(e){
	           r1 = 0;
	       }
	       try{
	           r2=num2.toString().split(".")[1].length;
	       }catch(e){
	           r2=0;
	       }
	       m=Math.pow(10,Math.max(r1,r2));

	       // return (num1*m+num2*m)/m;
	       return (Math.round(num1*m+num2*m)/m);
	    }

	    console.log(accAdd(1.22323,1.56545))
	</script>

</body>
</html>